package kr.hkit.androidcomplete02.ch19;

import kr.hyunist.androidcomplete01.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Toast;

public class UploadDelayedEx extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch19_upload);
	}


	
	Handler mHandler = new Handler(){

		@Override
		public void handleMessage(Message msg) {
			if(msg.what == 0){
				doUpload();
			}
		}
		
	};
	
	public void mOnClick(View v) {
		new AlertDialog.Builder(this).setTitle("질문").setMessage("업로드 하시겠습니까?")
				.setPositiveButton("예", new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						mHandler.sendEmptyMessageDelayed(0, 10);
					}
					
				}).setNegativeButton("아니오", null).show();
	}

	protected void doUpload() {
		for (int i = 0; i < 20; i++) {
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			Toast.makeText(this, "업로드를 완료했습니다.", 0).show();
		}
	}
}